package jmine.tec.web.wicket.component.menu.cfg;

import java.util.Arrays;
import java.util.List;

/**
 * Moves menus around
 * 
 * @author lundberg
 */
public class MenuConfigMover {

    private final MenuConfig menuConfig;

    private final List<String> from;

    /**
     * Constructor
     * 
     * @param menuConfig menuConfig
     * @param from from
     */
    public MenuConfigMover(MenuConfig menuConfig, List<String> from) {
        this.menuConfig = menuConfig;
        this.from = from;
    }

    /**
     * Effectively moves the menu item to the given destination. This operation might trigger a merge if there is a collision.
     * 
     * @param to to
     * @return MenuConfigItem
     */
    public MenuConfigItem to(String... to) {
        return this.to(Arrays.asList(to));
    }

    /**
     * Effectively moves the menu item to the given destination. This operation might trigger a merge if there is a collision.
     * 
     * @param to to
     * @return MenuConfigItem
     */
    public MenuConfigItem to(List<String> to) {
        MenuConfigItem moved = this.menuConfig.remove(this.from);
        return this.menuConfig.addItem(moved, to);
    }
}
